/**
 * 菜单JS
 */
angular.module('mall.menu', [
    "ngStorage"
])
.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
	$stateProvider
    //店铺列表页
        .state('index', {
            url: '/?menus&county&orderid',
            controller: 'IndexController'
        })
		//标签店铺列表页
        .state('mall.bytag',     {
            url : '/bytag/:area',
            templateUrl : cmt_mall_templateprefix+'/menu/bytag.html',
            resolve:{
                shoplist:['$stateParams','ShopService',function($stateParams,ShopService){
                    return ShopService.queryShoplistByScope($stateParams.area).$promise
                }]
            },
            controller : 'ByTagController'
        })
	;
}])
//农产品店铺列表
.controller('IndexController', ['$scope','$state','$stateParams',
    function($scope,$state,$stateParams) {
        if ($stateParams.menus) {
            $state.go('mall.bytag', {id:$stateParams.menus});
        } else if ($stateParams.county) {
            $state.go('county', {id:$stateParams.county});
        } else if ($stateParams.orderid) {
            $state.go('mall.placeorder', {orderid:$stateParams.orderid});
        }
}])
//餐谋团商城店铺列表
.controller('ByTagController', ['$scope','$state','$stateParams','$localStorage','ShopService','shoplist','AuthService', function($scope, $state,$stateParams, $localStorage,ShopService,shoplist,AuthService){
        $scope.ent_mallurl = projectBaseUrl;
        var $storage = $localStorage.$default({
            cmtname: '',
            cmtuserId: '',
            cmtwxpay_openid: '',
        });
        opacity_top();
        $scope.id = $stateParams.area;
        $scope.tagname = $stateParams.name;
        $scope.shoplist = [];
        if (shoplist.length == 0) {
            alert("该区域暂无商家");
        } else {
            for (var i = 0; i < shoplist.length; i++) {
                ShopService.queryShopByShopid(shoplist[i].shopid).$promise.then(function (data) {
                    $scope.shoplist.push(data);
                })
            }
        }
        console.log($scope.shoplist)
    //AuthService.setInfo($storage.userId,$storage.name,$storage.wxpay_openid);
}])
;
